﻿using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Send
{
    public class Program
    {
        public static void Main(string[] args)
        {
            const string queueName = "hello";
            Console.WriteLine("send start");
            var factory = new ConnectionFactory() ;
            factory.HostName = "192.168.64.130";
            factory.Port = 5672;
            factory.UserName = "root";
            factory.Password = "root";
            using (var conn=factory.CreateConnection())
            {
                using (var model=conn.CreateModel())
                {
                    model.QueueDeclare(queueName,false,false,false,null);
                    string msg = "my first rabbitmq project ";
                    var body = Encoding.UTF8.GetBytes(msg);

                    //model.ExchangeDeclare("exchange", ExchangeType.Direct);

                    //model.QueueBind("hello", "exchange", "hello-key", null);

                    model.BasicPublish(exchange: "",
                        routingKey: "hello",// 这才是receive的queueName
                        basicProperties: null,
                        body: body);

                    Console.WriteLine(" [x] send {0} ", msg);
                }
            }
            Console.WriteLine("send End ");
            Console.ReadLine();
        }
    }
}